import { NotFound } from 'lin-mizar';
import { Movie } from '../model/movie';

class MovieDao {

  static async getMovieList(){
    return await Movie.findAll();
  }

  static async addMovie(v){
    return await Movie.create(v);
  }

  static async editMovie(id, v){
    const movie = await Movie.findByPk(id);
    if(!movie){
      throw new NotFound();
    }

    return await movie.update({...v});
  }

  static async deleteMovie(id){
    const movie = await Movie.findByPk(id);
    if(!movie){
      throw new NotFound();
    }
    return await Movie.destroy({
      where: {
        id
      }
    })
  }

}

export { MovieDao };
